/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kungkhies.persistence.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author clayton
 */
@Entity 
@Table(name = "knode")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Knode.findAll", query = "SELECT k FROM Knode k"),
    @NamedQuery(name = "Knode.findByKnodeId", query = "SELECT k FROM Knode k WHERE k.knodeId = :knodeId"),
    @NamedQuery(name = "Knode.findByKnodeType", query = "SELECT k FROM Knode k WHERE k.knodeType = :knodeType"),
    @NamedQuery(name = "Knode.findByName", query = "SELECT k FROM Knode k WHERE k.name = :name"),
    @NamedQuery(name = "Knode.findByDisplayName", query = "SELECT k FROM Knode k WHERE k.displayName = :displayName")
})
public class Knode implements Serializable 
{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "knode_id")
    private Long knodeId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 8)
    @Column(name = "knode_type")
    private String knodeType;
    @Size(max = 256)
    @Column(name = "name")
    private String name;
    @Size(max = 256)
    @Column(name = "display_name")
    private String displayName;
    @Lob
    @Size(max = 16777215)
    @Column(name = "description")
    private String description;
    @JoinTable(name = "knode_ilo", joinColumns =
    {
        @JoinColumn(name = "knode_id", referencedColumnName = "knode_id")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "ilo_id", referencedColumnName = "ilo_id")
    })
    @ManyToMany
    private Collection<Ilo> iloCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "knode")
    private Collection<KungkhieKnode> kungkhieKnodeCollection;

    public Knode()
    {
    }

    public Knode(Long knodeId)
    {
        this.knodeId = knodeId;
    }

    public Knode(Long knodeId, String knodeType)
    {
        this.knodeId = knodeId;
        this.knodeType = knodeType;
    }

    public Long getKnodeId()
    {
        return knodeId;
    }

    public void setKnodeId(Long knodeId)
    {
        this.knodeId = knodeId;
    }

    public String getKnodeType()
    {
        return knodeType;
    }

    public void setKnodeType(String knodeType)
    {
        this.knodeType = knodeType;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getDisplayName()
    {
        return displayName;
    }

    public void setDisplayName(String displayName)
    {
        this.displayName = displayName;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    @XmlTransient
    public Collection<Ilo> getIloCollection()
    {
        return iloCollection;
    }

    public void setIloCollection(Collection<Ilo> iloCollection)
    {
        this.iloCollection = iloCollection;
    }

    @XmlTransient
    public Collection<KungkhieKnode> getKungkhieKnodeCollection()
    {
        return kungkhieKnodeCollection;
    }

    public void setKungkhieKnodeCollection(Collection<KungkhieKnode> kungkhieKnodeCollection)
    {
        this.kungkhieKnodeCollection = kungkhieKnodeCollection;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (knodeId != null ? knodeId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Knode))
        {
            return false;
        }
        Knode other = (Knode) object;
        if ((this.knodeId == null && other.knodeId != null) || (this.knodeId != null && !this.knodeId.equals(other.knodeId)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "com.kungkhies.persistence.entities.Knode[ knodeId=" + knodeId + " ]";
    }

}
